package com.atguigu.gateway.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.reactive.CorsWebFilter;
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;

//配置跨域的信息
@Configuration
public class MyCorsConfig {
    @Bean
    public CorsWebFilter corsWebFilter(){
        UrlBasedCorsConfigurationSource configurationSource=new UrlBasedCorsConfigurationSource();
        CorsConfiguration corsConfiguration=new CorsConfiguration();
//        所有请求头都可以跨越
        corsConfiguration.addAllowedHeader("*");
//        所有请求方式进行跨域
        corsConfiguration.addAllowedMethod("*");
//        允许所有请求来源跨域
        corsConfiguration.addAllowedOriginPattern("*");
//        允许cooke信息进行跨域
        corsConfiguration.setAllowCredentials(true);
        configurationSource.registerCorsConfiguration("/**",corsConfiguration);
        return new CorsWebFilter(configurationSource);
    }

}
